package com.wgts.wgts.mvp.presenter.imp;

import android.util.Log;

import com.wgts.wgts.mvp.model.IHomePageFragmentModel;
import com.wgts.wgts.mvp.presenter.IHomePageFragmentPersenter;
import com.wgts.wgts.mvp.view.IHomePageFragmentView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.resp.ProductClassEntity;
import com.wgts.wgts.netmodle.resp.UserInfoEntity;
import com.wgts.wgts.netmodle.resp.VipMessageEntity;
import com.wgts.wgts.tools.AppInfor;

import java.util.List;

public class HomePageFragmentPersenter implements IHomePageFragmentPersenter {

    private IHomePageFragmentView view;

    private IHomePageFragmentModel model;

    public HomePageFragmentPersenter(IHomePageFragmentView view, IHomePageFragmentModel model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void initProductClass() {
        model.initProductClass(new HttpResultSubscriber<List<ProductClassEntity>>() {
            @Override
            public void onSuccess(List<ProductClassEntity> productClassEntities) {
                view.initProductClassResult(productClassEntities);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
                Log.d("", "");
            }
        });
    }

    @Override
    public void userInfo() {
        model.userInfo(new HttpResultSubscriber<UserInfoEntity>() {
            @Override
            public void onSuccess(UserInfoEntity entity) {
                AppInfor.getInstance().setUserPhone(entity.userPhone);
                AppInfor.getInstance().setUserState(entity.userRole);
                AppInfor.getInstance().setAvailableBalance(entity.availableBalance);
                AppInfor.getInstance().setUserYQCode(entity.userCode);
                AppInfor.getInstance().setInviteCode(entity.userCode);
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });
    }

    @Override
    public void vipMessage() {
        model.vipMessage(new HttpResultSubscriber<List<VipMessageEntity>>() {
            @Override
            public void onSuccess(List<VipMessageEntity> vipMessageEntities) {
                view.vipMessage(vipMessageEntities);
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });
    }
}
